﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using service;

namespace BHTT.Baiviet
{
    public partial class Baiviet : System.Web.UI.Page
    {
        LoaibaivietService loaiBaiVietService = new LoaibaivietService();
        BaivietService baiVietService = new BaivietService();
        long idLoaibaiviet;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                setDataCombobox();
                dgrBaiviet.DataSource = baiVietService.getBaivietByLoai(Convert.ToInt64(cboLoaibaiviet.SelectedValue));
                dgrBaiviet.DataBind();
            }
            
        }

        private void setDataCombobox()
        {
            cboLoaibaiviet.DataSource = loaiBaiVietService.GetListAllLoaiBaiviet();
            cboLoaibaiviet.DataTextField = "Tenloaibai";
            cboLoaibaiviet.DataValueField = "ID";
            cboLoaibaiviet.DataBind();
        }
        protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        protected void RadioButtonList2_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void RadGrid_ItemCreated(object sender, GridItemEventArgs e)
        {

        }

        protected void RadGrid_ItemUpdated(object source, Telerik.Web.UI.GridUpdatedEventArgs e)
        {
            if (e.Exception != null)
            {
                e.KeepInEditMode = true;
                e.ExceptionHandled = true;
                DisplayMessage(true, "Customer " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["CustomerID"] + " cannot be updated due to invalid data.");
            }
            else
            {
                DisplayMessage(false, "Customer " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["CustomerID"] + " updated");
            }
        }

        protected void RadGrid_ItemInserted(object source, GridInsertedEventArgs e)
        {
            if (e.Exception != null)
            {
                e.ExceptionHandled = true;
                e.KeepInInsertMode = true;
                DisplayMessage(true, "Customer cannot be inserted due to invalid data.");
            }
            else
            {
                DisplayMessage(false, "Customer inserted");
            }
        }

        protected void RadGrid_ItemDeleted(object source, GridDeletedEventArgs e)
        {
            if (e.Exception != null)
            {
                e.ExceptionHandled = true;
                DisplayMessage(true, "Customer " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["CustomerID"] + " cannot be deleted");
            }
            else
            {
                DisplayMessage(false, "Customer " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["CustomerID"] + " deleted");
            }
        }

        private void DisplayMessage(bool isError, string text)
        {

        }

        protected void cboLoaibaiviet_SelectedIndexChanged1(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            idLoaibaiviet = Convert.ToInt64(e.Value);
            dgrBaiviet.DataSource = baiVietService.getBaivietByLoai(Convert.ToInt64(e.Value));
            dgrBaiviet.DataBind();
        }
    }
}